Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Example 1:Consider array has 4 elements and a... Start Learning for Free
Example 1:
Consider array has 4 elements and a searching element 16.
A[4]= {10, 16, 22, 25} 
The number of iterations are required to search an element by using a binary search= T1
Example 2:
Consider array has 4 elements and a searching element 22.
A[4]= {10, 16, 22, 25} 
The number of iterations are required to search an element by using a binary search= T2
Note: Searching is successful.
Q.Which of the following statement are true?
  • a)
    T1 = T2
  • b)
    T1 < T2
  • c)
    T1 >T2
  • d)
    T2 < T1
Correct answer is option 'B'. Can you explain this answer?
Most Upvoted Answer
Example 1:Consider array has 4 elements and a searching element 16.A[4...
The correct answer is option 2.
Concept:
Binary Search:
A Binary Search is a sorting method used to find a specific member in a sorted array. Because binary search works only on sorted arrays, an array must be sorted before using binary search on it. As the number of iterations in the binary search reduces, it is a superior searching approach to the liner search technique.
Algorithm:
int binarySearch(int a[], int beg, int end, int K)    
{    
    int mid;    
    if(end >= beg)     
    {   mid = (beg + end)/2;    
        if(a[mid] == K)                 
            return mid+1;    
        else if(a[mid] < K) 
            return binarySearch(a, mid+1, end, K);      
        else   
            return binarySearch(a, beg, mid-1, K);            
    }    
    return -1;     
}   
Example 1:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 16
beg= 0
end = 3
mid = 3/2 = 1
 if K with A[mid] and search is successful. 
Hence the number iterations are =1.
Example 2:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 22
beg= 0
end = 3
mid = 3/2 = 1.
Compare 22 with A[1] is not found and K is greater than A[mid]. So  call binarySearch(a, 1+1, 3, 2); 
beg= 2
end = 3
mid = 5/2 = 2.
Compare 22 with A[2] is found.
Hence the number of iterations is = 2
Hence the correct answer is T1 < T2.
Free Test
Community Answer
Example 1:Consider array has 4 elements and a searching element 16.A[4...
The correct answer is option 2.
Concept:
Binary Search:
A Binary Search is a sorting method used to find a specific member in a sorted array. Because binary search works only on sorted arrays, an array must be sorted before using binary search on it. As the number of iterations in the binary search reduces, it is a superior searching approach to the liner search technique.
Algorithm:
int binarySearch(int a[], int beg, int end, int K)    
{    
    int mid;    
    if(end >= beg)     
    {   mid = (beg + end)/2;    
        if(a[mid] == K)                 
            return mid+1;    
        else if(a[mid] < K) 
            return binarySearch(a, mid+1, end, K);      
        else   
            return binarySearch(a, beg, mid-1, K);            
    }    
    return -1;     
}   
Example 1:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 16
beg= 0
end = 3
mid = 3/2 = 1
 if K with A[mid] and search is successful. 
Hence the number iterations are =1.
Example 2:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 22
beg= 0
end = 3
mid = 3/2 = 1.
Compare 22 with A[1] is not found and K is greater than A[mid]. So  call binarySearch(a, 1+1, 3, 2); 
beg= 2
end = 3
mid = 5/2 = 2.
Compare 22 with A[2] is found.
Hence the number of iterations is = 2
Hence the correct answer is T1 < T2.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer?
Question Description
Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer?.
Solutions for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev